/**
 * IndexCtrl.java   2017年4月14日 下午4:46:27 by xuebing 
 *
 * Copyright (c) 2010 - 2017 All rights reserved.
 * 
 */
package com.rongmai.web.ctrl;

import com.rongmai.db.enums.DicTypeEnum;
import com.rongmai.db.enums.EnterpriseTypeEnum;
import com.rongmai.db.enums.OrgTypeEnum;
import com.rongmai.db.enums.UserRoleEnum;
import com.rongmai.db.model.BaseResult;
import com.rongmai.web.dto.ItemDTO;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/common")
public class CommonCtrl {

    @RequestMapping(value="/getEnum", method = RequestMethod.GET)
    public BaseResult<Map<String, List<ItemDTO>>> index(HttpServletRequest request){
        Map<String, List<ItemDTO>> map = new HashMap<>();

        List<ItemDTO> userRoles = new ArrayList<>();
        for (UserRoleEnum userRoleEnum : UserRoleEnum.values()) {
            userRoles.add(new ItemDTO(userRoleEnum.name(), userRoleEnum.getReferred(), userRoleEnum.getDesc()));
        }
        map.put("userRoles", userRoles);

        List<ItemDTO> enterpriseTypes = new ArrayList<>();
        for (EnterpriseTypeEnum enterpriseTypeEnum : EnterpriseTypeEnum.values()) {
            enterpriseTypes.add(new ItemDTO(enterpriseTypeEnum.name(), enterpriseTypeEnum.getDesc()));
        }
        map.put("enterpriseTypes", enterpriseTypes);

        List<ItemDTO> orgTypes = new ArrayList<>();
        for (OrgTypeEnum orgTypeEnum : OrgTypeEnum.values()) {
            orgTypes.add(new ItemDTO(orgTypeEnum.name(), orgTypeEnum.getDesc()));
        }
        map.put("orgTypes", orgTypes);

        List<ItemDTO> dicTypes = new ArrayList<>();
        for (DicTypeEnum dicTypeEnum : DicTypeEnum.values()) {
            dicTypes.add(new ItemDTO(dicTypeEnum.name(), dicTypeEnum.getDesc()));
        }
        map.put("dicTypes", dicTypes);

        return BaseResult.succ(map);
    }
}
